using Microsoft.AspNetCore.Mvc;
using ZR.Model.BaseManage.Dto;
using ZR.Model.BaseManage;
using ZR.Service.BaseManage.IBaseManageService;
using ZR.Admin.WebApi.Filters;

//创建时间：2025-04-22
namespace ZR.Admin.WebApi.Controllers.BaseManage
{
    /// <summary>
    /// plc标签信息
    /// </summary>
    [Verify]
    [Route("BaseManage/BasePlcTag")]
    public class BasePlcTagController : BaseController
    {
        /// <summary>
        /// plc标签信息接口
        /// </summary>
        private readonly IBasePlcTagService _BasePlcTagService;

        public BasePlcTagController(IBasePlcTagService BasePlcTagService)
        {
            _BasePlcTagService = BasePlcTagService;
        }

        /// <summary>
        /// 查询plc标签信息分页列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("pageList")]
        [ActionPermissionFilter(Permission = "base:plctag:list")]
        public IActionResult PageBasePlcTag([FromQuery] BasePlcTagQueryDto parm)
        {
            var response = _BasePlcTagService.GetPageList(parm);
            return SUCCESS(response);
        }

        
        /// <summary>
        /// 查询plc标签信息详情
        /// </summary>
        /// <param name="TagId"></param>
        /// <returns></returns>
        [HttpGet("{TagId}")]
        [ActionPermissionFilter(Permission = "base:plctag:query")]
        public IActionResult GetBasePlcTag(string TagId)
        {
            var response = _BasePlcTagService.GetInfo(TagId);
            
            var info = response.Adapt<BasePlcTagDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加plc标签信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "base:plctag:add")]
        [Log(Title = "plc标签信息", BusinessType = BusinessType.INSERT)]
        public IActionResult AddBasePlcTag([FromBody] BasePlcTagDto parm)
        {
            var modal = parm.Adapt<BasePlcTag>().ToCreate(HttpContext);

            var response = _BasePlcTagService.AddBasePlcTag(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新plc标签信息
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "base:plctag:edit")]
        [Log(Title = "plc标签信息", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateBasePlcTag([FromBody] BasePlcTagDto parm)
        {
            var modal = parm.Adapt<BasePlcTag>().ToUpdate(HttpContext);
            var response = _BasePlcTagService.UpdateBasePlcTag(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除plc标签信息
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete")]
        [ActionPermissionFilter(Permission = "base:plctag:delete")]
        [Log(Title = "plc标签信息", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteBasePlcTag([FromBody] string[] ids)
        {
            return ToResponse(_BasePlcTagService.Delete(ids));
        }

    }
}